home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d21 / asciitbl.arc / ASCIITBL.C next >
C/C++ Source or Header  |  1988-03-12  |  7KB  |  244 lines

  1. /************************************************************************
  2.  *    ASCII TABLE DISPLAY PROGRAM FOR USE WITH DESQVIEW        *
  3.  *                                    *
  4.  *    Copyright 1987, Phillip A. Kaufman. All rights, except those    *
  5.  *    specifically granted herein are reserved by the author. The right    *
  6.  *    to copy and distribute this material is granted without fee for    *
  7.  *    any and all non-commercial use. This material specifically may    *
  8.  *    not be distributed or sold for a fee nor incorporated in whole or    *
  9.  *    in part into any other product that is distributed or sold for a    *
  10.  *    fee without specific permission of the author. To obtain special    *
  11.  *    permission or to report any difficulties with this material    *
  12.  *    contact:                                *
  13.  *                      Phillip A. Kaufman                *
  14.  *                      19987 Moran Lane                *
  15.  *                      Saratoga, CA 95070                *
  16.  *                                    *
  17.  *    THIS MATERIAL IS DISTRIBUTES "as is" WITHOUT ANY EXPRESSED OR    *
  18.  *    IMPLIED WARRANTY OR LIABILITY FOR DIRECT, INDIRECT OR        *
  19.  *    CONSEQUENTIAL DAMAGES.                        *
  20.  ************************************************************************
  21.  *                                    *
  22.  *    Use: PgUp and PgDn to page the display - ESC to exit        *
  23.  *                                    *
  24.  *    Installation: Must be installed in Desqview environment.    *
  25.  *        Requires a DV memory size of only 4k. Must set the    *
  26.  *        window size to 18 high and 23 wide.            *
  27.  *        Program does not generate colors so it will assume    *
  28.  *        the window's colors or you can make a startup script    *
  29.  *        to force colors.                    *
  30.  *                                    *
  31.  *    Files:                                *
  32.  *        asciitbl.c    this source file ( for MSC 4.0;     *
  33.  *                  compile with small model and link     *
  34.  *                  with stack of 150 bytes - IT IS    *
  35.  *                  REALLY IMPORTANT to either use linker *
  36.  *                  directive to set stack or to use    *
  37.  *                  EXEMOD. Microsoft's default stack size*
  38.  *                  is 2k and program will crash DV if    *
  39.  *                  loaded into a 4k segment.)        *
  40.  *        asciitbl.exe    compiled version of above - fits in 4k    *
  41.  *                  with room to spare!            *
  42.  *        at-pif.dvp    dv 2.0 pif file                *
  43.  *        at-scrip.dvs    dv 2.0 startup script for colors    *
  44.  ************************************************************************/
  45.  
  46. #include    <dos.h>
  47. #define CASE case
  48. #define COLS 23        /* number of columns must be odd */
  49.             /* really not variable but convenient */
  50. char hex[] = "0123456789ABCDEF";
  51. int wind[] = {0,0x10,0x20,0x40,0x60,0x80,0xA0,0xC0,0xE0};
  52. int wcnt = 0;
  53. int first;
  54.  
  55. char head1[COLS/2] = "Dec Hex Chr";
  56. char head2[COLS/2] = "Ctrl  Use  ";
  57.  
  58. char use[32][4] = {"NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL","BS ",
  59. "HT ","LF ","VT ","FF ","CR ","SO ","SI ","DLE","DC1","DC2","DC3","DC4",
  60. "NAK","SYN","ETB","CAN","EM ","SUB","ESC","FS ","GS ","RS ","US "};
  61.  
  62. char *ptr;
  63. union REGS rg;            /* cpu regs        */
  64. struct SREGS segregs;
  65. union {
  66.     unsigned long l;    /* long form of address    */
  67.     char far *p;        /* pointer form of address */
  68. } addr, scptr;
  69.  
  70. _setargv()        /* dummy since we use no command line args */
  71. {
  72. }
  73. _setenvp()        /* dummy since we don't use environment variables */
  74. {
  75. }
  76. _nullcheck()        /* disable null pointer checking */
  77. {
  78. }
  79.  
  80. main()
  81. {
  82.     register int i;
  83.  
  84.         /* Check for Desqview and use its buffer */
  85.         rg.x.ax = 0x2B01;           /* do date set as DV check */
  86.         rg.x.cx = 0x4445;               /* "DESQ"an illegal date */
  87.         rg.x.dx = 0x5351;
  88.         int86(0x21,&rg,&rg);
  89.         if (rg.h.al != 0xFF){        /* we are in desqview    */
  90.                 rg.h.ah = 0xFE;        /* dv get buff addr    */
  91.         int86(0x10,&rg,&rg);
  92.         segread(&segregs);
  93.                 addr.l=((unsigned long)segregs.es<<16)+(unsigned long)rg.x.di;
  94.         }
  95.     else {
  96.         cputs ("\x07Program requires DESQview!\n");
  97.         exit(1);
  98.     }
  99.  
  100.     /* put up fixed part of header */
  101.         scptr.p = addr.p;
  102.     ptr = head1;
  103.     for (i = 0; i < COLS/2; i++){    /* 1st half of 1st line */
  104.         *scptr.p = *ptr++;
  105.         scptr.p = scptr.p +2;
  106.     }
  107.     scptr.p = addr.p + COLS*2;
  108.     for (i = 0; i < COLS; i++){    /* 2nd line */
  109.         *scptr.p = 0xC4;
  110.         scptr.p = scptr.p + 2;
  111.     }
  112.     
  113.     doit();        /* put up first screen */
  114.     
  115.     while (1) {      /* loop, wait for key then do it */
  116.         rg.h.ah = 0x07;        /* kbd input, wait, no echo */
  117.         int86(0x21,&rg,&rg);
  118.             if (rg.h.al == 0x1B) exit (0);    /* ESC */
  119.         if (rg.h.al == 0){
  120.             int86(0x21,&rg,&rg);
  121.             if (rg.h.al == 0x49){         /* PgUp */
  122.                 wcnt = (wcnt == 0)? 8 : wcnt -1;
  123.                 doit();
  124.             }
  125.             else if (rg.h.al == 0x51){     /* PgDn */
  126.                 wcnt = (wcnt == 8)? 0 : wcnt + 1;
  127.                 doit();
  128.             }
  129.         }
  130.     }
  131. }
  132.  
  133. doit()
  134. {
  135.     register int i;
  136.     char c;
  137.     register int l20;
  138.     first = wind[wcnt];
  139.     l20 = (first < 0x20);
  140.     
  141.     /* do variable header lines */
  142.         scptr.p = addr.p + COLS+1;    /* 2nd half of line 1 */
  143.         ptr = (l20)? head2 : head1;
  144.     for (i=0; i < COLS/2; i++){
  145.         *scptr.p = *ptr++;
  146.         scptr.p = scptr.p +2;
  147.     }
  148.     scptr.p = addr.p + COLS-1;    /* 1st line midpoint */
  149.     *scptr.p = (l20)? ' ' : 0xB3;
  150.     scptr.p = addr.p + (COLS*2) + (COLS -1) ; /*2nd line midpoint */
  151.     *scptr.p = (l20)? 0xC4 : 0xC5;
  152.     c = (l20)? ' ' : 0xB3;    /* center line */
  153.     scptr.p = addr.p + (COLS*4) + (COLS -1);
  154.     for (i = 0; i < 0x10; i++){
  155.         *scptr.p = c;
  156.         scptr.p = scptr.p + COLS*2;
  157.     }
  158.     
  159.     scptr.p = addr.p + COLS*4;
  160.     docol(0);    /* do 1st column */
  161.         
  162.     /* do 2nd col */
  163.     scptr.p = addr.p + (COLS*4) + (COLS + 1);
  164.     if (l20){
  165.         docol(1);
  166.     }
  167.     else {
  168.         first = first + 0x10;
  169.         docol(0);
  170.     }
  171.  
  172.     /* put the cursor outside the window */
  173.     rg.h.ah = 0x2;
  174.     rg.h.bh = 0;
  175.     rg.x.dx = 0x154f;  /* row 24 col 79*/
  176.     int86(0x10,&rg,&rg);
  177. }
  178.  
  179. docol(type)
  180. int type;
  181. {
  182.     int a, b, tcnt;
  183.     register int i, pos;
  184.     for ( i = first; i < first + 0x10; i++){
  185.         for ( pos = 0; pos < (COLS/2)-1; pos++){
  186.           if (type == 0){
  187.         switch (pos) {
  188.             CASE 0:
  189.                 a = i / 100;
  190.                         *scptr.p = (a == 0)? ' ': (a + 0x30);
  191.                         break;
  192.                     CASE 1:    /* 2nd decimal digit */
  193.                         b = (tcnt = i - a * 100) / 10;
  194.                         *scptr.p = (a == 0 && b == 0)? ' ': (b + 0x30);
  195.                         break;
  196.                     CASE 2:    /* 3rd decimal digit */
  197.                         *scptr.p = (tcnt - b * 10 + 0x30);
  198.                         break;
  199.             CASE 5:    /* 1st hex digit */
  200.                         *scptr.p = hex[ i >> 4];
  201.                 break;
  202.             CASE 6:    /* 2nd hex digit */
  203.                         *scptr.p = hex[ i & 0xF];
  204.                         break;
  205.             CASE 7:        /* blank to cover other format */
  206.             CASE 8:
  207.                 *scptr.p = ' ';
  208.                 break;
  209.             CASE 9:    /* character */
  210.                         *scptr.p = i;
  211.                 break;
  212.         }
  213.          }
  214.          else {
  215.                      switch (pos){
  216.             CASE 0:
  217.             CASE 5:
  218.             CASE 9:
  219.                 *scptr.p = ' ';
  220.                 break;
  221.             CASE 1:
  222.                         *scptr.p = '^';
  223.                         break;
  224.                     CASE 2:
  225.                         *scptr.p = i + 0x40;
  226.                         break;
  227.                     CASE 6:
  228.                         *scptr.p = use[i][0];
  229.                         break;
  230.                     CASE 7:
  231.                         *scptr.p = use[i][1];
  232.                         break;
  233.                     CASE 8:
  234.                         *scptr.p = use[i][2];
  235.                 break;
  236.         }
  237.          }    
  238.          scptr.p = scptr.p + 2;
  239.        }
  240.        scptr.p = scptr.p + COLS + 3;
  241.     }
  242.         return;
  243. }
  244.